Skip to content

Refactor Prim heap index handling - #112

Open
pruthvirajgojare-source wants to merge 2 commits into
S-AI-Projects:masterfrom
pruthvirajgojare-source:R23-T048
Open

pruthvirajgojare-source wants to merge 2 commits into
S-AI-Projects:masterfrom
pruthvirajgojare-source:R23-T048

Conversation

@pruthvirajgojare-source

@pruthvirajgojare-source pruthvirajgojare-source commented Nov 21, 2026 •

Copy link
Copy Markdown

Description

Refactors Prim's minimum spanning tree priority queue heap indexing to reduce duplicated arithmetic and simplify the downward heap adjustment. The change is intended to improve readability while preserving behavior.

Related Issue

No related issue identified.
Fixes: N/A (no related issue)

Type of Change

  • Bug Fix
  • New Feature
  • UI/UX Improvement
  • Performance Improvement
  • Tests
  • Documentation
  • Refactoring / Maintenance
  • CI/CD

Changes Made

  • get_child_right_position now derives its result from get_child_left_position(position) + 1.
  • _bubble_down chooses the smaller available child once before swapping, avoiding repeated child-weight/index handling.
  • Kept all existing doctests unchanged.
  • Added baseline and refactor evidence under work/R23-T048/.
  • C90: _bubble_down complexity decreased from 7 to 4; file-wide maximum remains prims_algo at 8 (below Ruff's default threshold of 10).

Screenshots / Recordings

Not applicable; no UI changes.

Testing

  • uvx ruff check graphs/minimum_spanning_tree_prims2.py — passed.
  • uvx ruff check --select C90 graphs/minimum_spanning_tree_prims2.py — passed.
  • uv run pytest graphs/minimum_spanning_tree_prims2.py — passed, 5 pytest items.
  • uv run python -m doctest -v graphs/minimum_spanning_tree_prims2.py — passed, all 24 doctests.
  • uv run pytest graphs/minimum_spanning_tree_prims2.py --cov=graphs.minimum_spanning_tree_prims2 --cov-report=term — passed, coverage 95% (baseline 93%).
  • uvx ruff format --check graphs/minimum_spanning_tree_prims2.py — passed.
  • 100 seeded randomized priority-queue trials with key updates and ordered extraction — passed.

Checklist

  • I have tested my changes locally.
  • I have added or updated tests, if needed. (Existing doctests were intentionally unchanged; randomized behavior checks were run.)
  • I have updated documentation, if needed. (Added the requested refactor report.)
  • I have followed the project's coding guidelines.
  • I have run the relevant tests and checks.
  • I have addressed previous review feedback, if applicable. (No review feedback received yet.)

Additional Notes

The task branch includes the code change and evidence files. A separate local upstream/R23-T048 branch contains only the code change; no upstream PR was opened. Baseline coverage was 93% (126 statements, 9 missed); after refactoring it is 95% (116 statements, 6 missed).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant